// src/main/java/com/example/servlet/GetTotalPriceServlet.java
package com.afishing.servlet;



import com.afishing.dao.CartDao;
import com.afishing.dao.impl.CartDapImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet("/getTotalPrice")
public class GetTotalPriceServlet extends HttpServlet {
    private CartDao cartDao;

    @Override
    public void init() throws ServletException {
        cartDao = new CartDapImpl();
    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        double totalPrice = cartDao.getTotalPrice();
        resp.setContentType("application/json");
        PrintWriter out = resp.getWriter();
        out.print("{\"totalPrice\": " + totalPrice + "}");
        out.flush();
    }
}